import { createStore } from 'vuex';
import { Itab } from './type';
//import appStore from "./appStore"
interface STATE{
    countVuex:number,
    tabList: Array<Itab>
}
let STATE =  {
    countVuex: 0,
}

export default createStore<STATE>({
    state(){
        return {
            countVuex: 0,
            tabList:[
              ]
        }
    },
    getters:{
        countVuex: (state: any) => state.countVuex,
        getAddTab(state:STATE){
            return state.tabList
        }
    },
    mutations:{
        ADD_ACOUNTVUEX(state: any, newCountVuex: Number) {
            state.countVuex = newCountVuex
        },
        REMOVE_TAB(state: STATE, targeName:string){
            const removeIndex = state.tabList.findIndex(item=>item.path === targeName)
            state.tabList.splice(removeIndex,1)
        },
        ADD_TAB(state: STATE, tab: Itab){
            const isSome = state.tabList.some(item=>{
                return item.path === tab.path
            })
            if(!isSome){
                state.tabList.push(tab)
            }
        },
    },
    actions:{
        ADD_ACOUNTVUEX(store: any, newCountVuex: Number) {
            store.commit('ADD_ACOUNTVUEX', newCountVuex)
        }
    },
//   modules: {
//       appStore
//   }
})